package com.yike.user.controller;

import com.yike.user.entity.UserSetting;
import com.yike.user.service.UserSettingService;
import lombok.extern.slf4j.Slf4j;
import com.yike.user.param.UserSettingPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.api.IdParam;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 用户设置表 控制器
 *
 * @author Sakura
 * @since 2024-09-12
 */
@Slf4j
@RestController
@RequestMapping("/userSetting")
@Module("user")
@Api(value = "用户设置表API", tags = {"用户设置表"})
@ApiIgnore
public class UserSettingController extends BaseController {

    @Autowired
    private UserSettingService userSettingService;

    /**
     * 添加用户设置表
     */
    @PostMapping("/add")
    @OperationLog(name = "添加用户设置表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加用户设置表", response = ApiResult.class)
    public ApiResult<Boolean> addUserSetting(@Validated(Add.class) @RequestBody UserSetting userSetting) throws Exception {
        boolean flag = userSettingService.saveUserSetting(userSetting);
        return ApiResult.result(flag);
    }

    /**
     * 修改用户设置表
     */
    @PostMapping("/update")
    @OperationLog(name = "修改用户设置表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改用户设置表", response = ApiResult.class)
    public ApiResult<Boolean> updateUserSetting(@Validated(Update.class) @RequestBody UserSetting userSetting) throws Exception {
        boolean flag = userSettingService.updateUserSetting(userSetting);
        return ApiResult.result(flag);
    }

    /**
     * 删除用户设置表
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除用户设置表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除用户设置表", response = ApiResult.class)
    public ApiResult<Boolean> deleteUserSetting(@PathVariable("id") Long id) throws Exception {
        boolean flag = userSettingService.deleteUserSetting(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取用户设置表详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "用户设置表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "用户设置表详情", response = UserSetting.class)
    public ApiResult<UserSetting> getUserSetting(@PathVariable("id") Long id) throws Exception {
        UserSetting userSetting = userSettingService.getById(id);
        return ApiResult.ok(userSetting);
    }

    /**
     * 用户设置表分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "用户设置表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "用户设置表分页列表", response = UserSetting.class)
    public ApiResult<Paging<UserSetting>> getUserSettingPageList(@Validated @RequestBody UserSettingPageParam userSettingPageParam) throws Exception {
        Paging<UserSetting> paging = userSettingService.getUserSettingPageList(userSettingPageParam);
        return ApiResult.ok(paging);
    }

}

